package inet.app.model.lottery;

import java.util.Collection;
import java.util.Vector;

public class GetLoto {
	public Collection<String> getEndNumberOfLotteryResult(LotteryResult lotteryResult, int n){		
		Vector<String> result = null;
		if(lotteryResult==null) return null;		
		int index=-1;
		String temp=null;
 		String addStr = "";
 		result = new Vector<String>();
			
		//Giai dac biet
		temp= lotteryResult.getSpecial();
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement(addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement(addStr);
				}
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		/*
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();		
			index=temp.indexOf('-');
			while(index!=-1){
				result.addElement(temp.substring(index-2, index));
				index=temp.indexOf('-', index+1);
			}
			result.addElement(temp.substring(temp.length()-2));	
		}
		*/	
		//Giai nhat
		temp= lotteryResult.getFirst();
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement(addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement(addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai nhi
		temp= lotteryResult.getSecond();
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement(addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement(addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai ba
		temp= lotteryResult.getThird();
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement(addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement(addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai tu
		temp= lotteryResult.getFourth();
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement(addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement(addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai nam
		temp= lotteryResult.getFifth();
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement(addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement(addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai sau
		temp= lotteryResult.getSixth();
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement(addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement(addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}

		//Giai bay
		temp= lotteryResult.getSeventh();
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement(addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement(addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}

		//Giai tam
		temp= lotteryResult.getEighth();
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement(addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement(addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
	
		return result;
	}
	public Collection<String> getEndNumberOfLotteryResult(LotteryResult lotteryResult){		
		Vector<String> result = null;
		int n=0;
		if(lotteryResult==null) return null;		
		int index=-1;
		String temp=null;
 		String addStr = "";
 		result = new Vector<String>();
			
		//Giai dac biet
		temp= lotteryResult.getSpecial();
		
		if(temp.contains("-"))
			n=temp.split("-")[0].length();
		else 
			n=temp.length();
		
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement("Đặc biệt: " + addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement("Đặc biệt: "+addStr);
				}
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai nhat
		temp= lotteryResult.getFirst();
		
		if(temp.contains("-"))
			n=temp.split("-")[0].length();
		else 
			n=temp.length();
		
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement("Giải nhất: "+addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement("Giải nhất: "+addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai nhi
		temp= lotteryResult.getSecond();
		if(temp.contains("-"))
			n=temp.split("-")[0].length();
		else 
			n=temp.length();
		
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement("Giải nhì: "+addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement("Giải nhì: "+addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai ba
		temp= lotteryResult.getThird();

		if(temp.contains("-"))
			n=temp.split("-")[0].length();
		else 
			n=temp.length();
		
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement("Giải ba: "+addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement("Giải ba: "+ addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai tu
		temp= lotteryResult.getFourth();

		if(temp.contains("-"))
			n=temp.split("-")[0].length();
		else 
			n=temp.length();
		
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement("Giải tư: "+addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement("Giải tư: "+addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai nam
		temp= lotteryResult.getFifth();

		if(temp.contains("-"))
			n=temp.split("-")[0].length();
		else 
			n=temp.length();
		
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement("Giải năm: "+addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement("Giải năm: "+addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
		
		//Giai sau
		temp= lotteryResult.getSixth();

		if(temp.contains("-"))
			n=temp.split("-")[0].length();
		else 
			n=temp.length();
		
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement("Giải sáu: "+addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement("Giải sáu: "+addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}

		//Giai bay
		temp= lotteryResult.getSeventh();

		if(temp.contains("-"))
			n=temp.split("-")[0].length();
		else 
			n=temp.length();
		
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement("Giải bảy: "+addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement("Giải bảy: "+addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}

		//Giai tam
		temp= lotteryResult.getEighth();
		System.out.println("GIAI 8 " + temp);
		if(temp!=null&&temp.contains("-"))
			n=temp.split("-")[0].length();
		else if(temp!=null&&!temp.contains("-"))
			n=temp.length();
		else 
			n=0;
		
		if(temp!=null && !temp.equals("")){
			temp=temp.trim();
			index = temp.indexOf('-');
			if(temp.lastIndexOf('-')+n<=temp.length()){
				addStr = temp.substring(temp.length()-n);
				if(addStr.indexOf('-') == -1) result.addElement("Giải tám: "+addStr);	
			}
			while(index!=-1){
				if(index>=n){
					addStr = temp.substring(index-n, index);
					if(addStr.indexOf('-') == -1) result.addElement("Giải tám: "+addStr);
				}				
				index=temp.indexOf('-', index+n+1);
			}			
		}
	
		return result;
	}
}
